package jsonlistview;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.android.volley.Response;
import com.example.administrator.myapplication.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import httptool.getHttpUrl;
import httptool.takeUrlResource;

/**
 * Created by cch on 2016/6/7.
 */
public class JsonDemo extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.item);
            getJson1();
    }
public void getJson1(){
    takeUrlResource.getJson(getApplicationContext(), getHttpUrl.index, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            try {
                JSONObject jso = new JSONObject(s);
                String st = jso.getString("retcode");
                if (st.equals("200")){
                    JSONArray jna = jso.getJSONArray("news");
                    for (int i = 0;i < jna.length();i++){
                        String title = jna.getJSONObject(i).getString("title");
                        String writer = jna.getJSONObject(i).getString("writer");
                        Log.e("这个是标题跟内容", title + "------>"+writer);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
}
